﻿/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * Author: Laurent WOUTERS
 */

using System;
using System.Collections.Generic;
using System.Text;
using Hime.Redist.Parsers;

namespace xowl.gmi.compiler.transform
{
    class PatternAST : Pattern
    {
        private PatternVariable var;
        private ast.MinimalAST ast;

        public PatternAST(PatternVariable var, ast.MinimalAST ast)
        {
            this.var = var;
            this.ast = ast;
        }
        public PatternAST(Context context, SyntaxTreeNode ast)
        {
            this.var = context.Resolve(((SymbolTokenText)ast.Children[0].Symbol).ValueText);
            this.ast = new ast.MinimalAST(ast.Children[1]);
        }

        public void Write(System.IO.StreamWriter writer)
        {
            writer.Write("    ");
            var.Write(writer);
            writer.Write(" = ");
            ast.Write(writer);
        }

        public void WriteOWL(System.IO.StreamWriter writer) { ast.WriteOWL(writer, var.ToString()); }
    }
}
